import http from './axios';

// 获取数据
export const getData = () => {
    return http.request({
        url: '/api/home/getData',
        method: 'get',
    }).catch(error => {
        console.error('获取数据错误:', error);
        throw error;
    });
};

// 获取用户信息，带可选参数
export const getUser = (params) => {
    return http.request({
        url: '/api/familymessage', 
        method: 'get',
        params
    }).catch(error => {
        console.error('获取用户信息错误:', error);
        throw error;
    });
};

// 创建新用户
export const createUser = (data) => {
    return http.request({
        url: '/api/familymessage', 
        method: 'post',
        data
    }).catch(error => {
        console.error('创建用户错误:', error);
        throw error;
    });
};

// 更新现有用户信息
export const updateUser = (data) => {
    return http.request({
        url: `/api/familymessage/${data.id}`, 
        method: 'put',
        data
    }).catch(error => {
        console.error('更新用户信息错误:', error);
        throw error;
    });
};

// 通过ID删除用户
export const deleteUser = (id) => {
    return http.request({
        url: `/api/familymessage/${id}`,
        method: 'delete'
    }).catch(error => {
        console.error('删除用户错误:', error);
        throw error;
    });
};

// 搜索用户
export const searchUsers = (params) => {
    return http.request({
        url: '/api/familymessage/search',
        method: 'get',
        params    
    }).catch(error => {         
        console.error('搜索用户错误:', error);
        throw error;
    }); 
};

